//src\renderer\Component\BarTop.vue
<script setup lang="ts">
import { onMounted, ref, onUnmounted } from "vue";
import { ipcRenderer } from "electron";
import { backupIndexedDB ,importDatabase } from "../utils/helper";
defineProps<{ title?: string }>();
let isMaximized = ref(false);

// debug窗口
let debugMainWindow = () => {
  ipcRenderer.invoke("openDevTools");
};
//关闭窗口
let closeWindow = () => {
  ipcRenderer.invoke("closeWindow");
};
//最大化窗口
let maxmizeMainWin = () => {
  ipcRenderer.invoke("maxmizeWindow");
};
//最小化窗口
let minimizeMainWindow = () => {
  ipcRenderer.invoke("minimizeWindow");
};
//还原窗口
let unmaximizeMainWindow = () => {
  ipcRenderer.invoke("unmaximizeWindow");
};
//窗口最大化事件
let winMaximizeEvent = () => {
  isMaximized.value = true;
};
//窗口取消最大化事件
let winUnmaximizeEvent = () => {
  isMaximized.value = false;
};
onMounted(() => {
  ipcRenderer.on("windowMaximized", winMaximizeEvent);
  ipcRenderer.on("windowUnmaximized", winUnmaximizeEvent);
});
onUnmounted(() => {
  ipcRenderer.off("windowMaximized", winMaximizeEvent);
  ipcRenderer.off("windowUnmaximized", winUnmaximizeEvent);
});
</script>

<template>
  <div class="topBar">
    <div class="winTitle">
      <img style="width: 20px; margin-right: 10px;" src="../assets/logo.png" alt="">
      <div>记忆笔记</div>
    </div>
    <div class="winTool">
      <!-- <div @click="debugMainWindow">
        <span class="iconfont icon-openDevTools"></span>
      </div> -->
      <div @click="backupIndexedDB">
        <i class="iconfont icon-download"></i>
      </div>
      <div @click="importDatabase">
        <i class="iconfont icon-update"></i>
      </div>
      <div @click="minimizeMainWindow">
        <span class="iconfont icon-minimizeWindow"></span>
      </div>
      <div v-if="isMaximized" @click="unmaximizeMainWindow">
        <span class="iconfont icon-huanyuan"></span>
      </div>
      <div v-else @click="maxmizeMainWin">
        <span class="iconfont icon-maxmizeWindow"></span>
      </div>
      <div @click="closeWindow">
        <span class="iconfont icon-closeWindow"></span>
      </div>
    </div>
  </div>
</template>

<style scoped>
.topBar {
  -webkit-app-region: drag;
  /* 启用拖拽 */
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  background-color: var(--surface-color);
  color: var(--text-primary);
  cursor: move;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.winTitle {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  font-family: '黑体';
}

.winTool {
  display: flex;
  flex-direction: row;
  gap: 12px;
}

.winTool > div {
  -webkit-app-region: no-drag;
  cursor: pointer;
  color: var(--text-primary);
  transition: var(--transition);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.winTool > div:hover {
  background-color: var(--primary-extra-light-color);
  color: var(--primary-color);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.winTool > div:last-child:hover {
  background-color: #ff5f56;
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 2px 8px rgba(255, 95, 86, 0.3);
}
</style>